<template>
  <div class="dialog-box">
    <el-dialog
      class="dialog"
      title="修改密码"
      :visible.sync="dialogFormVisible"
      width="400px"
    >
      <el-form :model="form" :rules="rules">
        <el-form-item
          :value="form.newpassword"
          prop="newpassword"
          label="新密码 :"
          :label-width="formLabelWidth"
        >
          <el-input
            type="password"
            v-model="form.newpassword"
            autocomplete="off"
          ></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click.native="cancel()">取 消</el-button>
        <el-button type="primary" @click.native="submit()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { Bus } from "../../Bus";
import { changepassword } from "../../api/datas";
export default {
  data() {
    return {
      dialogFormVisible: true,
      form: {
        newpassword: "",
        type: [],
      },
      formLabelWidth: "80px",
      user_id: "",
      isShowDialog1: false,
      disabled: true,
      rules: {
        newpassword: [
          { required: true,min:6,max:32, message: "请输入密码,密码长度位6至32位", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submit() {
      this.dialogFormVisible = false;
      Bus.$emit("isShowDialog1", this.isShowDialog1);
      if (this.form.newpassword.length >= 6 && this.form.newpassword.length <= 32) {
        changepassword({
          id: this.$store.state.usermsg.id,
          password: this.form.newpassword,
        }).then((res) => {
          alert(res.resoult);
        });
      }
    },
    cancel() {
      this.dialogFormVisible = false;
      Bus.$emit("isShowDialog1", this.isShowDialog1);
    },
  },
};
</script>

<style lang="less" scoped>
.item {
  width: 50px;
  height: 30px;
}
</style>
